package edu.thu.studio.ormdesigner.editor;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import edu.thu.studio.ormdesigner.editor.editpart.ColumnEditPart;
import edu.thu.studio.ormdesigner.editor.editpart.LinkEditPart;
import edu.thu.studio.ormdesigner.editor.editpart.DiagramEditPart;
import edu.thu.studio.ormdesigner.editor.editpart.TableNodeEditPart;
import edu.thu.studio.ormdesigner.editor.editpart.ViewNodeEditPart;
import edu.thu.studio.ormdesigner.model.diagram.Diagram;
import edu.thu.studio.ormdesigner.model.diagram.link.Link;
import edu.thu.studio.ormdesigner.model.diagram.node.TableNode;
import edu.thu.studio.ormdesigner.model.diagram.node.ViewNode;
import edu.thu.studio.ormdesigner.model.orm.table.Column;

public class EditorEditPartFactory implements EditPartFactory {
    
    public EditPart createEditPart(EditPart context, Object model) {
        EditPart editPart = null;
        
        if (model instanceof Diagram) {
            editPart = new DiagramEditPart();
        } else if (model instanceof TableNode) {
            editPart = new TableNodeEditPart();
        } else if (model instanceof ViewNode) {
            editPart = new ViewNodeEditPart();
        } else if (model instanceof Column) {
            editPart = new ColumnEditPart();
        } else if (model instanceof Link) {
            editPart = new LinkEditPart();
        }
        
        if (editPart != null) {
            editPart.setModel(model);
        }
        
        return editPart;
    }
}